<?php

namespace App\Http\Controllers;

use App\Common\Sql;
use Illuminate\Support\Facades\DB;

class ServerList extends Base
{

    public function logic()
    {

        $object =  DB::select("select * from t_server_info as a where 
        online_num = (select min(online_num) from t_server_info where a.server_flag=server_flag and status = 1) 
        group by server_flag;");

        foreach ($object as $key => $value) {
            $object[$key]->server_id = $value->id;
            $object[$key]->player_num = $value->online_num;
            unset($object[$key]->id);
            unset($object[$key]->online_num);
        }

        return $this->returnData(
            [
                'server_list' => $object
            ]
        );
    }

    public function detail()
    {
        $object             = DB::table('t_server_info')->where('id', $this->param['id'])->where('status', 1)->first();
        $object->server_id  = $object->id;
        $object->player_num = $object->online_num;
        unset($object->id);
        unset($object->online_num);
        return $this->returnData(['server_info' => $object]);
    }

}
